package com.dy.course.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.dy.course.common.BaseController;
import com.dy.course.common.ResponseMessage;
import com.dy.course.entity.ModifyUserInfo;
import com.dy.course.entity.UpdateOrCreateUser;
import com.dy.course.entity.UserInfo;
import com.dy.course.model.User;
import com.dy.course.service.IUserService;
import com.github.pagehelper.PageInfo;

@Controller
public class UserController extends BaseController{

	@Autowired
	private IUserService userService;
	
	
	@RequestMapping(value = "/user/update", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<?> updateUser(@RequestBody UpdateOrCreateUser user){
		logger.info("【修改用户信息】参数信息,query = "+JSON.toJSONString(user));
		userService.update(user);
		return constructNullResponse();
		
	}
	
	@RequestMapping(value = "/user/detail")
	@ResponseBody
	public ResponseMessage<User> qureyUser(@RequestParam(value="id") Long id){
		logger.info("【用户信息】参数信息,userId = "+id);
		UpdateOrCreateUser user = new UpdateOrCreateUser();
		user.setId(id);
		return constructResponse(userService.qureyById(user));
	}
	
	@RequestMapping(value = "/user/list")
	@ResponseBody
	public ResponseMessage<PageInfo<User>> qureyUser(UserInfo user){
		logger.info("【查询用户】参数信息,query = "+JSON.toJSONString(user));
		List<User> lst = userService.qurey(user);
		PageInfo<User> page = new PageInfo<User>(lst);
		return constructResponse(page);
	}
	
	
	@RequestMapping(value="/user/modify",method=RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<?> resetPassword(@RequestBody ModifyUserInfo rpi){
		userService.resetPassword(rpi);
		return constructNullResponse();
	}
}
